package cn.csc.module.shop.dal.mysql.recommend;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.module.shop.controller.admin.recommend.vo.ShopRecommendExportReqVO;
import cn.csc.module.shop.controller.admin.recommend.vo.ShopRecommendListReqVO;
import cn.csc.module.shop.controller.admin.recommend.vo.ShopRecommendPageReqVO;
import cn.csc.module.shop.dal.dataobject.recommend.ShopRecommendDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 店铺推荐记录 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface ShopRecommendMapper extends BaseMapperX<ShopRecommendDO> {

    default PageResult<ShopRecommendDO> selectPage(ShopRecommendPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopRecommendDO>()
                .eqIfPresent(ShopRecommendDO::getShopId, reqVO.getShopId())
                .likeIfPresent(ShopRecommendDO::getShopName, reqVO.getShopName())
                .eqIfPresent(ShopRecommendDO::getShopLogo, reqVO.getShopLogo())
                .likeIfPresent(ShopRecommendDO::getBusinessName, reqVO.getBusinessName())
                .eqIfPresent(ShopRecommendDO::getComment, reqVO.getComment())
                .eqIfPresent(ShopRecommendDO::getRecordDate, reqVO.getRecordDate())
                .betweenIfPresent(ShopRecommendDO::getCreateTime, reqVO.getCreateTime())
                .eq(ShopRecommendDO::getDeleted, 0)
                .orderByDesc(ShopRecommendDO::getId));
    }

    default List<ShopRecommendDO> selectList(ShopRecommendExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopRecommendDO>()
                .eqIfPresent(ShopRecommendDO::getShopId, reqVO.getShopId())
                .likeIfPresent(ShopRecommendDO::getShopName, reqVO.getShopName())
                .eqIfPresent(ShopRecommendDO::getShopLogo, reqVO.getShopLogo())
                .likeIfPresent(ShopRecommendDO::getBusinessName, reqVO.getBusinessName())
                .eqIfPresent(ShopRecommendDO::getComment, reqVO.getComment())
                .eqIfPresent(ShopRecommendDO::getRecordDate, reqVO.getRecordDate())
                .betweenIfPresent(ShopRecommendDO::getCreateTime, reqVO.getCreateTime())
                .eq(ShopRecommendDO::getDeleted, 0)
                .orderByDesc(ShopRecommendDO::getId));
    }

    default List<ShopRecommendDO> getRecommendListOfLatest(ShopRecommendListReqVO reqVO){
        return selectList(new LambdaQueryWrapperX<ShopRecommendDO>()
                .eqIfPresent(ShopRecommendDO::getRecordDate, reqVO.getRecordDate())
                .eq(ShopRecommendDO::getDeleted, 0)
                .last("limit "+reqVO.getNum())
                .orderByDesc(ShopRecommendDO::getCreateTime));
    }

}
